package com.iotek.ssm.controller;

import com.iotek.ssm.pojo.CustomQueryVo;
import com.iotek.ssm.pojo.Performance;
import com.iotek.ssm.pojo.PerformanceQueryVo;
import com.iotek.ssm.service.PerformanceService;
import com.iotek.ssm.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/performance")
public class PerformanceController {
    @Autowired
    private PerformanceService performanceService;

    @Autowired
    private Util util;

    @RequestMapping("/addPerformance")
//    @ResponseBody
    public String addPerformance(Model model,PerformanceQueryVo performanceQueryVo){
        System.out.println(performanceQueryVo);
        List<Performance> performances = performanceQueryVo.getPerformances();
        try {
            performanceService.addPerformances(performances);
            util.setJumpDetails(model,"添加成功！","返回首页！","../admin/managePageJump",1);
        } catch (Exception e) {
            e.printStackTrace();
            util.setJumpDetails(model,"添加失败！","返回首页！","../admin/managePageJump",1);
        }
        return "jumpPage";
    }

    @RequestMapping("/performances")
    @ResponseBody
    public List<Performance> performances(CustomQueryVo customQueryVo){
        customQueryVo.setDate(new Date());
        List<Performance> performances = null;
        try {
            performances = performanceService.findPerformance(customQueryVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return performances;
    }
}
